package com.lyfei.yd.system.domain.entity;

import com.lyfei.yd.system.domain.dto.SkuInfoDto;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class OrderSku {

    private Long id;
    private Long spuId;
    private BigDecimal finalPrice;
    private BigDecimal singlePrice;
    private List<String> specValues;
    private Integer count;
    private String img;
    private String title;

    public OrderSku(Sku sku, SkuInfoDto skuInfoDto) {

        this.id = sku.getId();
        this.spuId = sku.getSpuId();
        this.singlePrice = sku.getPrice();
        this.finalPrice = sku.getPrice().multiply(new BigDecimal(skuInfoDto.getCount()));
        this.count = skuInfoDto.getCount();
        this.img = sku.getImg();
        this.title = sku.getTitle();
        this.specValues = sku.getSpecKeyValues().stream().map(SpecKeyValue::getValue).collect(Collectors.toList());
    }
}
